import { Effect, Reducer, Subscription } from 'umi';
import { getAccessList,getListacc } from "@/services";

export interface IndexModelState {
    accessList: [];
}

export interface IndexModelType {
    namespace: 'access';
    state: IndexModelState;
    effects: {
        getaccessList: Effect;
        getlistacc:Effect;
    };
    reducers: {
        save: Reducer<IndexModelState>;
        // 启用 immer 之后
        // save: ImmerReducer<IndexModelState>;
    };
    subscriptions?: { setup: Subscription };
}

const Access: IndexModelType = {
    namespace: 'access',

    state: {
        accessList: []
    },

    effects: {
         *getlistacc({payload},{call,put}){
             let result =yield call(getListacc);
             console.log(result,"1212121");
         },
        // 获取数字
        *getaccessList({ payload }, { call, put }) {
            let result = yield call(getAccessList, payload.params);
            console.log(result);
            yield put({
                type: 'save',
                payload: {
                    accessList: result.data[0]
                }
            })
        },
    },
    reducers: {
        save(state, action) {
            return {
                ...state,
                ...action.payload,
            };
        },
        // 启用 immer 之后
        // save(state, action) {
        //   state.name = action.payload;
        // },
    },

};

export default Access;